!function (t) {
    function n(e) {
        if (r[e]) return r[e].exports;
        var i = r[e] = {exports: {}, id: e, loaded: !1};
        return t[e].call(i.exports, i, i.exports, n), i.loaded = !0, i.exports
    }

    var r = {};
    return n.m = t, n.c = r, n.p = "", n(0)
}([function (t, n, r) {
    r(1)(window)
}, function (t, n) {
    t.exports = function (t) {
        var n = "RealXMLHttpRequest";
        t.hookAjax = function (t) {
            function r(n) {
                return function () {
                    var r = this.hasOwnProperty(n + "_") ? this[n + "_"] : this.xhr[n], e = (t[n] || {}).getter;
                    return e && e(r, this) || r
                }
            }

            function e(n) {
                return function (r) {
                    var e = this.xhr, i = this, o = t[n];
                    if ("function" == typeof o) e[n] = function () {
                        t[n](i) || r.apply(e, arguments)
                    }; else {
                        var u = (o || {}).setter;
                        r = u && u(r, i) || r;
                        try {
                            e[n] = r
                        } catch (t) {
                            this[n + "_"] = r
                        }
                    }
                }
            }

            function i(n) {
                return function () {
                    var r = [].slice.call(arguments);
                    if (!t[n] || !t[n].call(this, r, this.xhr)) return this.xhr[n].apply(this.xhr, r)
                }
            }

            return window[n] = window[n] || XMLHttpRequest, XMLHttpRequest = function () {
                var t = new window[n];
                for (var o in t) {
                    var u = "";
                    try {
                        u = typeof t[o]
                    } catch (t) {
                    }
                    "function" === u ? this[o] = i(o) : Object.defineProperty(this, o, {
                        get: r(o),
                        set: e(o),
                        enumerable: !0
                    })
                }
                this.xhr = t
            }, window[n]
        }, t.unHookAjax = function () {
            window[n] && (XMLHttpRequest = window[n]), window[n] = void 0
        }, t.default = t
    }
}]);
hookAjax({
    onreadystatechange: function (xhr) {
    }, onload: function (xhr) {
        var responseIndex =  xhr.response.indexOf('{');
        if (responseIndex == 0) {
            var responseJson = JSON.parse(xhr.response);
            if (responseJson.code == 2000) {
                top.location.href = responseJson.loginUrl;
            }
        }
    }, open: function (arg) {
    }
});
var msgtitle = '提示';

var lay_tz_ui = {
    itWin: {
        /**
         * 提示框
         * @param {string} content 提示内容
         * @param {string} icon "1 代表对号图标、2 错误图标 3 疑问图标 4 锁定图标 5 哭脸图标 6微笑图标 7感叹号"
         * @param {function} fn 提示后操作方法
         * */
        alert: function (content, icon, fn) {
            var _default = {
                "content": content,
                "options": undefined,
                "fn": function (index) {
                    if (typeof (fn) == "function") {
                        fn();
                    }
                    layer.close(index);
                }
            };
            var opicon = icon;
            if (!isNaN(icon)) {
                opicon = 7;
            } else if (typeof (icon) == "function") {
                _default.fn = function (index) {
                    icon();
                    layer.close(index);
                };
                opicon = 7;
            }
            _default.options = {
                title: msgtitle,
                icon: opicon
            };
            return layer.alert(_default.content, _default.options, _default.fn);
        },
        /**
         * 询问框
         * @param {string} content 提示内容
         * @param {string} icon "1 代表对号图标、2 错误图标 3 疑问图标 4 锁定图标 5 哭脸图标 6微笑图标 7感叹号"
         * @param {function} fn 提示后操作方法
         */
        confirm: function (content, icon, fn) {
            var _default = {
                "content": content,
                "options": undefined,
                "fn": function (index) {
                    if (typeof (fn) == "function") {
                        fn();
                        layer.close(index);
                    }
                }
            };
            var opicon = icon;
            if (!isNaN(icon)) {
                opicon = icon;
            } else if (typeof (icon) == "function") {
                _default.fn = function (index) {
                    icon();
                    layer.close(index);
                };
                opicon = 3;
            }
            _default.options = {
                title: msgtitle,
                icon: opicon
            };

            return layer.confirm(_default.content, _default.options, _default.fn);
        },
        confirm2: function (content, btn1, btn2, fnok, fncancel) {
            return layer.confirm(content, {
                btn: [btn1, btn2], //按钮
                title: msgtitle,
                icon: 3
            }, function () {
                fnok();
            }, function () {
                fncancel();
            });
        },
        /**
         * 提示框
         * @param {string} content 提示内容
         * @param {string} icon "1 代表对号图标、2 错误图标 3 疑问图标 4 锁定图标 5 哭脸图标 6微笑图标 7感叹号"
         * @param {function} fn 提示后操作方法
         */
        msg: function (content, icon, fn) {
            var _default = {
                "content": content,
                "options": undefined,
                "fn": function () {
                    if (typeof (fn) == "function") {
                        fn();
                    }
                }
            };
            if (!isNaN(icon)) {
                _default.options = {
                    time: 1000,
                    shade: .01,
                    icon: icon
                };
            } else if (typeof (icon) == "function") {
                _default.fn = function () {
                    icon();
                };
            } else if (typeof (icon) == "object") {
                _default.options = icon;
            }

            return layer.msg(_default.content, _default.options, _default.fn);
        },

        /**
         * tips层
         * @param {string} content 提示内容
         * @param {Object} follow 对象标识， 例如  '#id'或者'.class'
         * @param {string} position 显示位置 top、left、bottom、right
         */
        tips: function (content, follow, position) {
            var _position = {
                "top": 1,
                "left": 2,
                "bottom": 3,
                "right": 4
            };

            if (!!position) {
                position = _position[position];
            } else {
                position = _position.right;
            }
            return layer.tips(content, follow, {
                tips: [position, '#000']
            });
        },
        //
        /**
         * 重置特定弹出框
         * @param {Object} option 配置基本参数
         * */
        open: function (option) {
            var _default = {
                type: 2, //基本层类型 1页面层 2 iframe层
                title: false, //标题
                shadeClose: false, // 是否点击遮罩关闭
                maxmin: false, //开启最大化最小化按钮
                shade: [0.1, '#393D49'], //遮罩  shade: [0.8, '#393D49']   false 代表关闭
                area: ['80%', '80%'], // 宽高
                offset: 'auto', //坐标
                time: 0, //自动关闭所需毫秒  0 不关闭
                shift: 2, //动画 不支持ie6-9   参数 0~6
                content: "", //['test/guodu.html', 'no'], //iframe的url，no代表不显示滚动条
                end: function () { //层销毁后触发的回调
                }
            };
            $.extend(true, _default, option);
            var winindex;
            winindex = layer.open(_default);
            if (_default.full) {
                layer.full(winindex);
            }
            return winindex;
        },
        opentab: function (option) {
            var _default = {
                type: 2, //基本层类型 1页面层 2 iframe层
                shadeClose: false, // 是否点击遮罩关闭
                maxmin: false, //开启最大化最小化按钮
                shade: [0.1, '#393D49'], //遮罩  shade: [0.8, '#393D49']   false 代表关闭
                area: ['80%', '80%'], // 宽高
                offset: 'auto', //坐标
                time: 0, //自动关闭所需毫秒  0 不关闭
                shift: 2
            };
            $.extend(true, _default, option);
            var winindex;
            winindex = layer.tab(_default);

            return winindex;
        },
        iframeAuto: function (index) { //指定iframe层自适应
            layer.iframeAuto(index);
        },
        /**
         * 加载层
         * @param {Number} type 加载图标 支持传入0-2如果是0，无需传
         * @param {Object} option 配置基本参数
         * */
        load: function (option) {
            //			var type = 2;
            var _defualt = {
                type: 1,
                shade: [0.1, '#000000']
            };
            $.extend(true, _defualt, option);
            var type = _defualt.type;
            delete _defualt.type;
            return layer.load(type, _defualt);
        },
        min: function (index) {
            layer.min(index);
        },
        full: function (index) {
            layer.full(index);
        },
        restore: function (index) {
            layer.restore(index);
        },
        setTop: function (layero) {
            layer.setTop(layero);
        },
        /**
         * 关闭特定层
         * @param {Object} index 每一种弹层调用方式，返回的一个index 例如：var index = layer.tips();
         */
        close: function (index) {
            layer.close(index);
        },
        /**
         * 关闭特定层
         * @param {string} 层的类型，如果未写参数则标识关闭所有层； 例如 dialog 所有信息框，page 所有页面层 type
         * */
        closeAll: function (type) {
            if (!!type) {
                layer.closeAll(type);
            } else {
                layer.closeAll(); //疯狂模式，关闭所有层
            }
        }
    },
    tools: {
        dateFormat: function (dateTime, type, isHour) {
            if (typeof (dateTime) == "string") {
                dateTime = new Date(dateTime.split(" ")[0]);
            } else if (typeof (dateTime) == "number") {
                dateTime = parseInt(dateTime) > 10000000000 ? parseInt(dateTime) : parseInt(dateTime) * 1000;
                dateTime = new Date(dateTime);
            }
            var strDate = "";
            if (!!dateTime) {
                var year = dateTime.getFullYear();
                var month = dateTime.getMonth() + 1;
                var day = dateTime.getDate();
                if (type == 1) {
                    strDate = year + '年' + ((month > 9) ? month : '0' + month) + '月' + ((day > 9) ? day : '0' + day) + "日";
                } else {
                    strDate = year + '-' + ((month > 9) ? month : '0' + month) + '-' + ((day > 9) ? day : '0' + day);
                }
                if (!!isHour) {
                    var oh = dateTime.getHours();
                    var omi = dateTime.getMinutes();
                    var os = dateTime.getSeconds();
                    strDate += " " + (oh > 9 ? oh : "0" + oh) + ":" + (omi > 9 ? omi : "0" + omi) + ":" + (os > 9 ? os : "0" + os);
                }
            }
            return strDate;
        },
        secondsFormat: function (time) {
            var timeStr = '';
            var stringFormat = function(i)

            {
                return i < 10 ? '0'+i : i;
            }
            var minuteTime = 0;
            var secondTime = 0;
            var hourTime = 0;
            if (time < 60) {
                timeStr = '00:00:stringFormat(time)';
            } else if (time >= 60 && time < 3600) {
                minuteTime = parseInt(time / 60);
                secondTime = parseInt(time % 60);
                timeStr = '00:'+stringFormat(minuteTime)+':'+stringFormat(secondTime);
            } else if (time >= 3600) {
                var _t = parseInt(time % 3600);
                hourTime = parseInt(time / 3600);
                minuteTime = parseInt(_t / 60);
                secondTime = parseInt(_t % 60);
                timeStr = stringFormat(hourTime)+':'+stringFormat(minuteTime)+':'+stringFormat(secondTime)
            }
            return timeStr;
        },
        fileNameWithPath: function (path) {
            if (path != null && path.length > 0) {
                var pathResults = path.split('\/');
                return pathResults[pathResults.length - 1];
            } else {
                return '';
            }
        },
        strToFloat: function (str) {
            if (str == null || str == '' || str == 'undefined') {
                return 0;
            } else {
                var result = parseFloat(str);
                if (isNaN(result)) {
                    return 0;
                } else {
                    return result;
                }
            }
        },
        strToInt: function (str) {
            if (str == null || str == '' || str == 'undefined') {
                return 0;
            } else {
                var result = parseInt(str);
                if (isNaN(result)) {
                    return 0;
                } else {
                    return result;
                }
            }
        },
        isEmptyStr: function (obj) {
            if (typeof obj == "undefined" || obj == null || obj == "") {
                return true;
            } else {
                return false;
            }
        }
    },
    /**
     * item：ajax的配置参数
     * 描述：访问服务端数据交互
     **/
    dataAjax: function (item) {
        var _default = {
            "url": null, //发送请求的地址。
            "async": false, //是否设置为异步  false 同步，true 异步
            "cache": false, //是否缓存
            "data": null, //数据
            "contentType": "application/x-www-form-urlencoded; charset=utf-8",
            "dataType": "json", // (默认: Intelligent Guess (xml, json, script, or html))
            "timeout": "1200000", //设置请求超时时间（毫秒）
            "type": item.type, //请求类型 (比如i "POST", "GET", "PUT");， 默认为 "GET"
            "beforeSend": function () {
            },
            "success": function (result) {
            }, //请求成功后的回调函数。
            "error": function () {
            }, //请求失败时调用此函数。
            "complete": function (XMLHttpRequest, textStatus) {
            }, //请求完成后回调函数 (请求success 和 rror之后均调用)。
            "loading": null //加载中  相对面板
        };
        $.extend(true, _default, item);
        var sendData = _default.data;
        var _url = _default.url;
        if (!sendData) {
            _default.data = {};
        }
        $.extend(true, _default.data, sendData);
        var plObj;
        _default.beforeSend = function (result) {
            if (!!_default.loading) {
                plObj = _default.loading.pageLoading();
                plObj.Init();
            }
            if (typeof item.beforeSend == "function") {
                item.beforeSend(result);
            }
        };
        _default.success = function (result) {
            if (typeof item.success == "function") {
                item.success(result);
            }
        };
        _default.complete = function (XMLHttpRequest, textStatus) {
            try {
                var code = XMLHttpRequest.responseJSON.code;
                var loginUrl = XMLHttpRequest.responseJSON.loginUrl;
                if (code == 700) {
                    top.location.href = loginUrl;
                } else {
                    // var rtext = JSON.parse(XMLHttpRequest.responseText);
                    // if (rtext.code == "0") {
                    //     top.location = rtext.redirectUrl;
                    // }
                }
            } catch (e) {
                //TODO handle the exception
            }
            if (!!_default.loading) {
                plObj.Close();
            }
            if (typeof item.complete == "function") {
                item.complete(XMLHttpRequest, textStatus);
            }
        };
        return $.ajax(_default);
    },


    cookieUtil: {
        setCookie: function setCookie(cName, cValue, exDays) {
            var d = new Date();
            d.setTime(d.getTime() + (exDays * 24 * 60 * 60 * 1000));
            var expires = "expires=" + d.toUTCString();
            document.cookie = cName + "=" + cValue + ";" + expires + ";path=/";
        },
        getCookie: function getCookie(cName) {
            var name = cName + "=";
            var decodedCookie = decodeURIComponent(document.cookie);
            var ca = decodedCookie.split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0) == ' ') {
                    c = c.substring(1);
                }
                if (c.indexOf(name) == 0) {
                    return c.substring(name.length, c.length);
                }
            }
            return "";
        }

    },

    /**
     * 文件预览
     */
    filePreView: {
        previewFile: function previewFile(name, path) {
            var fileType = name.substring(name.lastIndexOf(".") + 1);
            if (name == null || name == '') {
                fileType = path.substring(name.lastIndexOf(".") + 1);
            }
            if (/(jpg|JPG|JPEG|jpeg|png|PNG|gif|GIF)$/.test(fileType)) {
                layer.photos({
                    photos: {
                        "title": "图片预览", //相册标题
                        "id": 123, //相册id
                        "start": 0, //初始显示的图片序号，默认0
                        "data": [   //相册包含的图片，数组格式
                            {
                                "alt": name,
                                "pid": 666, //图片id
                                "src": path, //原图地址
                                "thumb": path //缩略图地址
                            }
                        ]
                    }
                    , anim: 1 //0-6的选择，指定弹出图片动画类型，默认随机
                });
            } else {
                window.open(path);
            }
        },
    },
    /**
     * 上传文件回显
     * @param fileName 文件名称
     */
    uploadFileShow: {
        /**
         * 上传文件
         * @param root 显示文件路径（本地）
         * @param filePath 上传文件的路径（上传的全路径）
         * @param fileName 文件名称
         * @returns {string}
         */
        uploadFile: function (root, filePath, fileName) {
            var files = fileName.split(".");
            var returnStr = "<div class=\"fileShow\">";
            var fileSuffix = "." + files[1];
            if (/\.(jpg|JPG|JPEG|jpeg|png|PNG|gif|GIF)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + filePath + '" width=\'200px\' height=\'100px\'>';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else if (/\.(dox|docx|docm|dotx|dotm)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/word.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else if (/\.(xlsx|xlsm|xltx|xltm|xlsb|xlam)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/excel.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else if (/\.(pptx|pptm|ppsx|ppsx|potx|potm|ppam)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/ppt.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else if (/\.(rar|zip|RAR|ZIP)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/zip.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/files.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            }
            returnStr += '<span class="delBtn" style="color: red;cursor: pointer;z-index: auto;">';
            returnStr += '<i class="layui-icon layui-icon-close" style="font-weight: bold"></i>';
            returnStr += '</span>';
            returnStr += '</div>';
            return returnStr;
        },
        /**
         * 上传文件
         * @param root 显示文件路径（本地）
         * @param filePath 上传文件的路径（上传的全路径）
         * @param fileName 文件名称
         * @returns {string}
         */
        downloadFile: function (root, filePath, fileName) {
            var files = fileName.split(".");
            var returnStr = "<div class=\"fileShow\">";
            var fileSuffix = "." + files[1];
            if (/\.(jpg|JPG|JPEG|jpeg|png|PNG|gif|GIF)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + filePath + '" width=\'200px\' height=\'100px\'>';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else if (/\.(dox|docx|docm|dotx|dotm)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/word.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else if (/\.(xlsx|xlsm|xltx|xltm|xlsb|xlam)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/excel.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else if (/\.(pptx|pptm|ppsx|ppsx|potx|potm|ppam)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/ppt.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else if (/\.(rar|zip|RAR|ZIP)$/.test(fileSuffix)) {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/zip.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            } else {
                returnStr += '<div style="text-align: center;margin-bottom: 10px;margin-top: 10px;">';
                returnStr += '<img src="' + root + '/common/images/files.png" width="80px" height="80px;">';
                returnStr += '</div>';
                returnStr += '<div style="text-align: center">';
                returnStr += '<a href="' + filePath + '" target="_blank">' + fileName + '</a>';
                returnStr += '</div>';
            }
            returnStr += '<span class="delBtn" style="color: red;cursor: pointer;z-index: auto;">';
            returnStr += '<i class="layui-icon layui-icon-close" style="font-weight: bold"></i>';
            returnStr += '</span>';
            returnStr += '</div>';
            return returnStr;
        }
    }
};

var dataCols = ''; //列表cols

(function ($) {
    /*****
     * @NAME 下拉框
     * ******/
    $.fn.selectDrop = function (_option) {
        var _this = this;
        var _default = {
            data: [],
            url: "",
            type: "",
            width: "",
            isSearch: true,
            placeholder: '请选择',
            params: {},
            required: false,
            filter: '',
            optionVal: "",
            optionId: "",
            changeEvent: function () {

            }
        };
        $.extend(true, _default, _option);
        var dataObj = '';
        var config = {
            init: function () {
                if (_default.data.length > 0) {
                    setDataHtml(_default.data)
                } else {
                    $.ajax({
                        url: _default.url,
                        type: _default.type,
                        data: _default.params,
                        success: function (cols) {
                            if (cols.code == 0) {
                                dataObj = cols.data;
                                setDataHtml(dataObj)
                            } else if (cols.errorCode == 0) {
                                dataObj = cols.data;
                                setDataHtml(dataObj)
                            }
                        }
                    });
                }

                function setDataHtml(dataObj) {
                    layui.use('form', function () {
                        var $select = '<form class="layui-form" style="width: ' + _default.width + '">';
                        if (_default.isSearch) {
                            if (_default.required) {
                                $select += '<select lay-search lay-verify="required" lay-filter="' + _default.filter + '">';
                            } else {
                                $select += '<select lay-search   lay-filter="' + _default.filter + '">';

                            }
                        } else {
                            if (_default.required) {
                                $select += '<select lay-verify="required" lay-filter="' + _default.filter + '">';
                            } else {
                                $select += '<select  lay-filter="' + _default.filter + '">';
                            }
                        }
                        if (_default.optionVal != "") {
                            $select += '<option value="' + _default.optionId + '">' + _default.optionVal + '</option>';
                        } else {
                            $select += '<option value="">' + _default.placeholder + '</option>';
                        }
                        dataObj.forEach(function (o, i) {
                            $select += '<option value="' + o.id + '" text="' + o.text + '">' + o.text + '</option>';
                        });
                        $select += '</select></form>';
                        $(_this).append($select);

                        var form = layui.form;
                        form.render("select");            // 刷新 select，显示出数据
                        form.on('select(' + _default.filter + ')', function (data) {
                            var id = data.value;
                            var val = $(_this).find('.layui-this').text();
                            return _default.changeEvent(id, val)
                        });
                    });
                }
            }
        };

        config.init();

        return this;
    }

})(jQuery);

/*******
 * @NAME 列表
 * ***********/

(function ($) {
    $.fn.layDataGrid = function (_option) {
        var _this = this;
        var table, editData = '', checkBox = [];
        var _default = {
            elem: '',
            url: "",
            method: "",
            where: "",
            height: '',
            contentType: 'application/json',
            page: true,
            cols: null,
            isRowspan:false,
            click: function () {

            },
            dblclick: function () {

            },
            complated: function (list) {

            },
            getCols: function (cols) {

            }
        };
        $.extend(true, _default, _option);
        $(_this).attr('lay-filter', _default.elem);
        layui.use('table', function () {
            table = layui.table;
            //第一个实例
            var cols = '';
            if(_default.isRowspan){
                cols =_default.cols
            }else {
               cols =[_default.cols]
            }
            dataCols = cols;
            table.render({
                elem: '#' + _default.elem,
                height: _default.height,
                url: _default.url, //数据接口
                method: _default.method,
                where: _default.params || null,
                contentType: _default.contentType,
                page: _default.page, //开启分页
                limit: 25,
                limits: [25, 50, 100, 200],
                loading: true,
                cols: cols,
                parseData: function (res) { //res 即为原始返回的数据
                    var resData = res.data.data;
                    if (!_default.page) {
                        resData = res.data;
                    }
                    _default.complated(resData);
                    _default.getCols(_default.cols);
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.count, //解析数据长度
                        "data": resData //解析数据列表
                    }
                }
            });
            var delObj = null;
            //监听行单击事件
            table.on('row(' + _default.elem + ')', function (obj) {
                editData = '';
                $(obj.tr[0]).css('backgroundColor', '#b9eada');
                // $(obj.tr[0]).find('div').css("color","#fff");
                $(obj.tr[0]).siblings('tr').css('backgroundColor', 'transparent');
                $(obj.tr[0]).siblings('tr').find('div').css('color', '#333');
                obj.data.trDataIndex = obj.tr.attr('data-index');
                editData = obj.data; //得到当前行数据
                _this.getTabData(obj.data);
                return _default.click(editData)
            });
            //监听行双击事件
            table.on('rowDouble(' + _default.elem + ')', function (obj) {
                return _default.dblclick(obj.data)
            });

            table.on('checkbox(' + _default.elem + ')', function (obj) {
                obj.data.trDataIndex = obj.tr.attr('data-index');
                delObj = obj;
                if (obj.type == 'one') {
                    if (obj.checked) {
                        checkBox.push(obj.data);
                    } else {
                        checkBox.forEach(function (col, index) {
                            if (col.id == obj.data.id) {
                                checkBox.splice(index, 1);
                            }
                        })
                    }
                } else {
                    var checkStatus = table.checkStatus(_default.elem);
                    if (checkStatus.data.length > 0) {
                        checkStatus.data.forEach(function (col, index) {
                            col.trDataIndex = index;
                        })
                    }
                    checkBox = checkStatus.data
                }
                //console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
            });

            table.on("sort(" + _default.elem + ")", function (obj) {
                table.reload(_default.elem, {
                    where: obj,
                    page: {
                        curr: 1
                    }
                });
            });

            //获取选中行
            _this.getLayCheckeds = function () {
                return checkBox
            };

            //刷新
            _this.LoadLayDatagrid = function () {
                //刷新时清空勾选的数据列表
                checkBox = [];
                //刷新的时候清空正在编辑的元素 Add by Peihang 2019-11-07
                editData = null;
                table.reload(_default.elem, {
                    page: {
                        curr: 1
                    }
                });

            };
            //删除一行
            _this.tableDeleteRow = function (rows, callback) {
                rows.forEach(function (col, index) {
                    if (col.trDataIndex != undefined) {
                        $('div[lay-id="' + _default.elem + '"]').find(".layui-table-body").find('tr[data-index=' + col.trDataIndex + ']').remove();
                    }
                })
                checkBox = [];
                return callback;

            }
            //单击行数据
            _this.getTabData = function () {
                return editData || ''
            }

            //獲取cols
            _this.getCols = function () {
                return _default.cols
            }

            //根据条件进行搜索
            _this.refreshTab = function (obj) {
                if(_default.page){
                    table.reload(_default.elem, {
                        where: obj,
                        page: {
                            curr: 1
                        }
                    });
                }else {
                    table.reload(_default.elem, {
                        where: obj
                    });
                }

            }
        });
        return this;
    }
})(jQuery);

(function () {
    $.fn.tabCheck = function (_option) {
        var _this = this;
        var _default = {
            data:'',
            elem:''
        };
        $.extend(true, _default, _option);
        layui.use('form', function () {
        var htmlTop = '<div class="tabScreen" style="position: relative">' +
            '<div class="tabTop"><span class="layui-icon layui-icon-cols" style="font-size: 20px"></span></div>' +
            '<div class="tabBody"></div>' +
            '</div>';
        var html = '<form class="layui-form">';
        _default.data.forEach(function (o,i) {
          if (!o.hide && o.type != 'checkbox' && o.type != 'number') {
                    html += '<div class="screenList"><input type="checkbox" value="' + o.field + '" title="' + o.title + '" lay-skin="primary" lay-filter="tabScreen" checked></div>';
             }
        });
        html += '</form>';
        $(_this).append(htmlTop);
        $(_this).find('.tabBody').append(html);
            var form = layui.form;
            form.render("checkbox");
            $(_this).on('click','.tabTop',function(){
                $(_this).find('.tabBody').show();
            });

            form.on('checkbox(tabScreen)', function(data){
                var isShow = data.elem.checked; //是否被选中，true或者false
                var field = data.value; //复选框value值，也可以通过data.elem.value得到
                if(isShow){
                    $('div[lay-id='+_default.elem+']').find('table').find('th[data-field='+field+']').show();
                    $('body').find('table').find('td[data-field='+field+']').show();
                }else {
                    $('body').find('table').find('th[data-field='+field+']').hide();
                    $('body').find('table').find('td[data-field='+field+']').hide();
                }

            });
            $(document).click(function(e){
                var _con = $(_this).find('.tabScreen');   // 设置目标区域
                if(!_con.is(e.target) && _con.has(e.target).length === 0){
                    $(_this).find('.tabBody').hide();
                }
            });
        });

        return this;
    }
})(jQuery);

/***********
 *  @NAME 操作按钮  刷新 ，添加 ，编辑 ， 删除
 * ******************/

(function ($) {
    $.fn.toolbar = function (_option) {
        var _this = this;
        var _default = {
            text: "",
            title: "",
            icon: '',
            click: function () {

            }
        }
        $.extend(true, _default, _option);
        var config = {
            init: function () {
                if (_default.btn.length > 0) {
                    var $btn = '';
                    var _btn = {};
                    _default.btn.forEach(function (o, i) {
                        $.extend(true, _btn, _default, o);
                        if (o.text == "|") {
                            $btn += '<button  class="layui-btn layui-btn-sm" style="background-color: #fff;color: #333"><span>|</span></button>';
                        } else {
                            if (o.type != undefined) {
                                $btn = '<button type="button" class="layui-btn layui-btn-sm ' + o.type + '"   title="' + o.text + '" style="position: relative;top: 4px;">';
                            } else {
                                $btn = '<button type="button" class="layui-btn layui-btn-sm "  title="' + o.text + '" style="position: relative;top: 4px;">';
                            }
                            $btn += '<i class="layui-icon ' + o.icon + '"></i>';
                            $btn += o.text;
                            $btn += '</button>';
                        }

                        $(_this).append($btn);
                    });
                    config.clickOption(_btn.btn);
                }
            },

            clickOption: function (_btn) {
                $(_this).on('click', '.layui-btn', function () {
                    var index = $(this).index();
                    return _btn[index].click()
                });

            }
        };
        config.init();
        return this;
    }
})(jQuery);

/**********
 *  @NAME  搜索
 * **********************/

(function ($) {
    $.fn.toolSearch = function (_option) {
        var _this = this;
        var _default = {
            width: "",
            placeholder: "",
            searchEvent: function () {
            }
        };

        $.extend(true, _default, _option);

        _this.init = function () {
            var $search = ' <input type="text" name="search" id="LaySearch" placeholder="' + _default.placeholder + '" autocomplete="off" class="layui-input" style="padding-right: 40px;">'
            $search += '<span class="layui-icon layui-icon-search" style="position: absolute;top: 10px;right: 15px;"></span>'
            $(_this).append($search)
        };
        _this.init();
        $(_this).on('keyup', '#LaySearch', function (e) {
            var val = $(this).val();
            var keyCode = e.keyCode;
            if (keyCode == 13) {
                _this.searchData(val)
            }

        });
        $(_this).on('click', '.layui-icon-search', function () {
            var val = $('[name="search"]').val();
            _this.searchData(val)
        });

        _this.searchData = function (val) {
            return _default.searchEvent(val)

        }
        return this;
    }
})(jQuery);

jQuery.fn.rowspan = function(colIdx) { //封装的一个JQuery小插件 
    return this.each(function(){
        var that;
        $('tr', this).each(function(row) {
            $('td:eq('+colIdx+')', this).filter(':visible').each(function(col) {
                if (that!=null && $(this).attr("class") == $(that).attr("class")) {
                    rowspan = $(that).attr("rowSpan");
                    if (rowspan == undefined) {
                        $(that).attr("rowSpan",1);
                        rowspan = $(that).attr("rowSpan"); 
                    }
                    rowspan = Number(rowspan)+1;
                    $(that).attr("rowSpan",rowspan);
                    $(this).hide();
                } else {
                    num=1;
                    that = this;
                }
            });
        });
    });
} 

